/**
 * 
 */
package com.yidin.lsc;

import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.content.Intent;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.RadioGroup;
import android.widget.Spinner;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemSelectedListener;

/**
 * 大小相亲界面
 * 
 * @author cola
 * 
 */
public class Blinddate extends Container {
	private Button listBtn;
	private Button speedDialBtn;
	private Button mapBtn;
	private Button rightBtn;
	private ViewGroup ViewContainer;
	protected ListView myListView;
	private List<View> group;
	protected List<BlindDateList> netInfos = null;
	protected BlindDateAdapter addressListAdapter;

	public Blinddate(Activity activity, View contentView,Views father) {
		super(activity, contentView, father);
		// TODO Auto-generated constructor stub
		initialize();
	}

	@Override
	public void checkCache() {
		// TODO Auto-generated method stub

	}

	@Override
	public void findView(View contentView) {
		// TODO Auto-generated method stub
		View view = null;
		view = inflater.inflate(R.layout.talk, null);
		group.add(view);

		ViewContainer.addView(view);

		this.listBtn = (Button) contentView.findViewById(R.id.list);
		this.listBtn.setText("列表");
		this.speedDialBtn = (Button) contentView.findViewById(R.id.speedDial);
		this.speedDialBtn.setVisibility(View.GONE);
		this.mapBtn = (Button) contentView.findViewById(R.id.map);
		this.mapBtn.setText("宫格");
		this.rightBtn = (Button) contentView.findViewById(R.id.filter);
		this.rightBtn.setText("精选");
		
	}

	@Override
	public void showFunctionsListView(View contentView) {
		// TODO Auto-generated method stub
		this.group = new ArrayList<View>();
		ViewContainer = (ViewGroup) contentView
				.findViewById(R.id.ViewContainer);
	}

	@Override
	public void initialize() {
		// TODO Auto-generated method stub
		this.netInfos = new ArrayList<BlindDateList>();
		BlindDateList a = new BlindDateList();
		a.imageUrl = "";
		a.introduce = "互联网的一点事";
		a.sex = true;
		a.name = "要命";
		netInfos.add(a);
		BlindDateList a2 = new BlindDateList();
		a2.imageUrl = "";
		a2.introduce = "www.yidin.net";
		a2.sex = true;
		a2.name = "小明";
		netInfos.add(a2);
		
		this.myListView = (ListView) contentView
				.findViewById(R.id.myFriendListView);
		addressListAdapter = new BlindDateAdapter(activity,netInfos);
		this.myListView.setAdapter(addressListAdapter);
		this.rightBtn.setOnClickListener(filterOnClickListener);
	}

	public void removeView() {
		ViewContainer.removeAllViews();
	}

	private String[] sex = new String[] { "不限","男", "女" };
	private boolean select = false;
	private OnClickListener filterOnClickListener = new OnClickListener() {

		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			if (select == false) {
				View view = inflater.inflate(R.layout.blinddatefilter, null);
				ViewContainer.getChildAt(0).setVisibility(View.GONE);
				if (ViewContainer.getChildCount() > 1)
					ViewContainer.removeViewAt(1);
				ViewContainer.addView(view);

				Spinner sexSpinner = (Spinner) activity
						.findViewById(R.id.spinnerSex);
				ArrayAdapter<String> adapter = new ArrayAdapter<String>(
						activity, android.R.layout.simple_spinner_item, sex);
				// 设置下拉列表的风格
				adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
				sexSpinner.setAdapter(adapter);
				sexSpinner.setOnItemSelectedListener(itemSelect);
				select = true;
			}else{
				ViewContainer.getChildAt(1).setVisibility(View.GONE);
				ViewContainer.getChildAt(0).setVisibility(View.VISIBLE);
				select = false;
			}
		}

	};
	
	private OnItemSelectedListener itemSelect = new OnItemSelectedListener() {

		@Override
		public void onItemSelected(AdapterView<?> parent, View view,
				int position, long id) {
			// TODO Auto-generated method stub
//			if (parent.getItemAtPosition(position).toString().equals("男"))
//				userSex = "1";
//			else
//				userSex = "0";
		}

		@Override
		public void onNothingSelected(AdapterView<?> parent) {
			// TODO Auto-generated method stub

		}
	};
	
	@Override
	public void refresh(Object... param) {
		// TODO Auto-generated method stub
		
	}

	public class BlindDateList{
		public String name;
		public String introduce;
		public String status;
		public boolean sex;
		public String imageUrl;
	}
}
